package cn.bluech.lib.rxandroid;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Description:
 * Created by Codeant on 2019/4/10.
 */
public abstract class SimpleObserver<T> implements Observer<T> {
    private T result;
    private Throwable err;

    @Override
    public void onSubscribe(Disposable d) {
    }

    @Override
    public void onNext(T t) {
        result = t;
    }

    @Override
    public void onError(Throwable e) {
        err = e;
        onResult(false);
    }

    @Override
    public void onComplete() {
        onResult(true);
    }

    public T getResult() {
        return result;
    }

    public Throwable getThrowable() {
        return err;
    }

    public String getErrMsg() {
        return null!=err?err.getMessage():"";
    }

    protected abstract void onResult(boolean isSuccess);
}
